package com.ruoyi.web.controller.V2.web.conntroller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.system.gen.IGenAPI;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.service.ISysUserService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@RequestMapping("/qrCode/cf")
@RestController
public class CFDataController {


    @Autowired
    private IGenAPI genAPI;


    /**
     * 获取登录验证
     */
    @GetMapping("/getXLLogin")
    public AjaxResult tdCode(@RequestParam Map<String, Object> params) {
        String gameId = MapUtils.getString(params,"gameId");
        String type = MapUtils.getString(params,"type");
        return AjaxResult.success(genAPI.tdCfCode(gameId,type));
    }


    /**
     * 获取校验结果
     */
    @GetMapping("/getXLLoginFindRe")
    public AjaxResult getXLLoginFindRe(@RequestParam Map<String, Objects> params) {
        String uuid = MapUtils.getString(params,"uuid");
        String gameId = MapUtils.getString(params,"gameId");
        String type = MapUtils.getString(params,"type");
        JSONObject loginFindRe = genAPI.getXLLoginFindRe(uuid, gameId, type);
        if (Objects.nonNull(loginFindRe)) {
            return AjaxResult.success(loginFindRe);
        } else {
            return AjaxResult.error();
        }
    }

    /**
     * 获取游戏数据
     */
    @GetMapping("/getXLGameInfo")
    public AjaxResult getXLGameInfo(@RequestParam Map<String, Objects> params) {
        String tencentId = MapUtils.getString(params,"tencentId");
        String gameId = MapUtils.getString(params,"gameId");
        JSONObject info = genAPI.getXLGameInfo(tencentId, gameId);
        if (Objects.nonNull(info)) {
            return AjaxResult.success(info);
        } else {
            return AjaxResult.error();
        }
    }

}
